<template>
    <div>
        <el-form ref="form" :model="obj.data" label-width="100px">
            <el-form-item label="是否通过" prop="verify" :rules="[formRulesMixin.notNull]">
                <el-switch v-model="obj.data.verify" size="small" :validate-event="true"
                    :active-text="obj.data.verify==1?'通过':'拒绝'" inactive-text=""
                    active-value="1" inactive-value="2">
                </el-switch>
            </el-form-item>
            <el-form-item label="车位号" prop="parking_id" :rules="[formRulesMixin.notNull]" v-if="obj.data.verify==1">
                <el-select v-model="obj.data.parking_id"
                    filterable remote reserve-keyword
                    placeholder="请输入车位关键字" :remote-method="remoteMethod" :loading="loading">
                    <el-option v-for="item in obj.options" :key="item.parking_id" :label="item.name" :value="item.parking_id"/>
                </el-select>
            </el-form-item>
            <el-form-item label="承租时间" prop="starttime" :rules="[formRulesMixin.notNull]" v-if="obj.data.verify==1">
                <DatePicker v-model:value="obj.data.starttime" />
            </el-form-item>
            <el-form-item label="到期时间" prop="endtime" :rules="[formRulesMixin.notNull]" v-if="obj.data.verify==1">
                <DatePicker v-model:value="obj.data.endtime" />
            </el-form-item>
            <el-form-item class="dialog-btns-item">
                <div class="dialog-btns">
                    <span class="btn clear" @click="$emit('close')">取消</span>
                    <span class="btn sub ml10" @click.prevent="upData">提交</span>
                </div>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup>
    import { reactive,ref,getCurrentInstance,toRaw,inject } from 'vue'
    import DatePicker from '@/components/date_picker.vue'
    let { proxy } = getCurrentInstance()
    let obj = reactive({
        data:{
            parking_apply_id: inject("id").value || 0,
            verify: '1',
            parking_id:"",
            starttime:"",
            endtime:""
        },
        options: []
    })

    let setDate = d => { return d <= proxy.$utils.dateAddDay(new Date(), -1) }
    let init = async () => {
    }
    init()
    let upData = () => {
        proxy.$refs['form'].validate(valid => {
            if (valid) {
                console.log(obj.data);
                // return
                proxy.$ajax({
                    url: 'parking_apply//setstate',
                    data: obj.data,
                    bfLoading: true,
                }).then(d => {
                    if(d.success){
                        proxy.elMessageMixin(`审核成功`, 'success')
                        proxy.$emit('init')
                        proxy.$emit('close')
                    }else{
                        proxy.elMessageMixin(d.err, 'error')
                    }
                }).catch(() => { })
            }else{
                return false
            }
        })
    }

    const remoteMethod = async (query) => {
        proxy.$ajax({url: 'parking/list_for',data: {key:query,can:1},bfLoading: true,}).then(d => {
            if(d.success){
                obj.options = d.msg.list;
            }else{
                obj.options = []
            }
        }).catch(() => {
            obj.options = []
        })
    }
    
</script>

<style scoped>
</style>